package com.cjm.lecode;

import java.util.HashMap;
import java.util.Map;

public class Ti1 {
    public static int[] one(long[] nums, long target) {
        Map<Long, Integer> xx = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            long arg = nums[i];
            long key = target - arg;
            Integer integer = xx.get(key);
            if (integer != null) {
                if (i < integer) {
                    return new int[]{i, integer};
                } else {
                    return new int[]{integer, i};
                }
            }
            xx.put(arg, i);
        }
        return null;
    }

    public static void main(String[] args) {
        int[] one = one(new long[]{2, 7, 11, 15}, 9);
        System.err.println(one[0] + "," + one[1]);
        int[] two = one(new long[]{3, 2, 4}, 6);
        System.err.println(two[0] + "," + two[1]);
        int[] three = one(new long[]{3, 3}, 6);
        System.err.println(three[0] + "," + three[1]);
    }
}
